package com.byzk.p2p.admin.score.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import com.byzk.p2p.admin.base.controller.AdminBaseController;
import com.byzk.p2p.admin.base.util.JsonMsg;
import com.byzk.p2p.admin.base.util.PageInfo;
import com.byzk.p2p.admin.score.dto.ScoreRecord;
import com.byzk.p2p.admin.score.service.ScoreRecordService;
import com.byzk.p2p.admin.score.vo.ScoreRecordVo;

@Controller
@RequestMapping("/admin/scoreRecord")
public class ScoreRecordController extends AdminBaseController {
	
	@Autowired
	private ScoreRecordService scoreRecordService;
	
	@RequestMapping("/list")
	public String listScoreRecord(Model model,
			   @RequestParam(value="index",required=false,defaultValue="1") int index,
			   @RequestParam(value="limit",required=false,defaultValue="10") int limit,
			   @RequestParam(value="scoreRecord",required=false) ScoreRecordVo scoreRecord){
		scoreRecord = new ScoreRecordVo();
		scoreRecord.setIndex(index);
		scoreRecord.setLimit(limit);
		PageInfo<ScoreRecordVo> pageInfo=scoreRecordService.listScoreRecord(scoreRecord);
		model.addAttribute("pageInfo", pageInfo);
		return ftl(Thread.currentThread().getStackTrace());
	}
	
	/**
	 * 根据id获得积分流水  相关记录
	 * @param model
	 * @param id
	 * @return
	 */
	@RequestMapping("/show")
	public String showScoreRecordById(Model model,@RequestParam(value="id") Integer id){
		ScoreRecord scoreRecord = scoreRecordService.getScoreRecordById(id);
		model.addAttribute("scoreRecord", scoreRecord);
		return ftl(Thread.currentThread().getStackTrace());
	}
	
	
	/**
	 * 新增，修改积分流水 方法
	 * @param scoreRecord
	 * @return
	 */
	@RequestMapping("/update")
	public String updateScoreRecord(ScoreRecord scoreRecord){
		try {
			scoreRecord.setTerminal("PC");
			Integer i = scoreRecordService.saveScoreRecord(scoreRecord);
			if(i>0){
				super.printJSON(new JsonMsg(-1,"操作成功",i));
			}else{
				super.printJSON(new JsonMsg(0,"操作失败",""));
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
		return null;
	}
}
